<?php

namespace app\controller;

use app\model\Area;
use app\model\Fh;
use app\model\FhOil;
use app\model\Stations;

class Test
{
    public function index()
    {
        $gas = (new Fh)->paginate(500);
        $area = (new Area);
        $items = [];
        foreach ($gas as $value) {
            $items[] = [
                "name" => $value['name'],
                "province" => $value['province'],
                "city" => $value['city'],
                "country" => $value['country'],
                "address" => $value['address'],
                "logo_small" => $value['logo_small'],
                "logo_big" => $value['logo_big'],
                "lat" => $value['lat'],
                "lng" => $value['lng'],
                "intro"=> $value['intro'],
                "service"=>$value['service'],
                "business_time"=>$value['business_time'],
                "start"=>$value['start'],
                "brand_desc"=>$value['brand_desc'],
                "type"=>$value['type'],
                "state"=>$value['status'],
                "at_from"=>1,
                "gas_id"=>$value['gas_id']
            ];
        }

        return json(['ecode'=>$items]);
    }

    public function oil()
    {
        $gas_id = (new Stations)->where('at_from', 1)->column('id','gas_id');
        $data = app(FhOil::class)->select()->toArray();
        $its = array_map(function ($item) use ($gas_id) {
            return array_merge($item, ['station_id' => $gas_id[$item['gas_id']]]);
        }, $data);
//        dd($its);
        return json(['ecode'=>$its]);
    }

    public function qrcodDate()
    {
//        $qrcode = QrCode::createFromString(file_get_contents("./123456.png"));
//        return $qrcode->getData();
    }
}
